package top.yehot.kettle.boot.service.impl;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import top.yehot.cmm.util.core.base.BaseException;
import top.yehot.cmm.util.core.model.vo.LabelValueVO;
import top.yehot.kettle.boot.enums.DeleteEnum;
import top.yehot.kettle.boot.enums.KettleResEnum;
import top.yehot.kettle.boot.mapper.DatabaseTypeMapper;
import top.yehot.kettle.boot.models.entity.DatabaseType;
import top.yehot.kettle.boot.service.DatabaseTypeService;

/**
 * 数据库类型 服务实现类
 * 
 * @author lquan
 * @date 2022年5月10日 上午11:42:48
 */
@Service
public class DatabaseTypeServiceImpl extends ServiceImpl<DatabaseTypeMapper, DatabaseType> implements DatabaseTypeService {

	@Override
	public List<LabelValueVO> getAll() {
		List<DatabaseType> dtList = baseMapper.selectList(Wrappers.lambdaQuery(DatabaseType.class).eq(DatabaseType::getDelFlag, DeleteEnum.no));
		Optional.ofNullable(dtList).orElseThrow(() -> new BaseException(KettleResEnum.DB_TYPE_NOT_EXIST));
		return dtList.stream().map(e -> LabelValueVO.of(e.getCode(), e.getDescription())).collect(Collectors.toList());
	}

}
